package com.foreknow.demo08;

/**
 * 设计一个类Student，该类包括姓名、学号和成绩。设计一个方法，
 * 按照成绩从高到低的顺序输出姓名、学号和成绩信息。[选做题]
 */

public class Student {
    int id;
    String name;
    int score;

    public Student(int id,String name,int score) {
        this.id = id;
        this.name = name;
        this.score = score;
    }

    public Student[] getSort(Student[] stu) {
        for(int i = 1;i<stu.length;i++){
            for(int j = 0;j<stu.length-i;j++){
                if(stu[j].score<stu[j+1].score){
                    Student temp = stu[j];
                    stu[j] = stu[j+1];
                    stu[j+1] = temp;
                }
            }
        }
        return stu;
    }

    public static void main(String[] args) {
        Student st1 = new Student(101,"张三",90);
        Student st2 = new Student(102,"李四",80);
        Student st3 = new Student(103,"王五",100);

        Student[] s = {st1,st2,st3}; //向数组中保存元素
        Student[] students = st2.getSort(s);//调用排序的方法
        for(int i = 0;i<students.length;i++){
            Student stu = students[i];
            System.out.println(stu.id+"--"+stu.name+"--"+stu.score);
        }


        //    Student[] ss = new Student[3];
        //
        //    ss[0] = st1;
        //    ss[1] = st2;
        //    ss[2] = st3;
    }

}